﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EjemploSVN.Models;

namespace EjemploSVN.DataAccess
{
    public class DefaultUnitOfWork : IUnitOfWork
    {

        private ModelContext dbContext;        
        /// <summary>
        /// EF context.
        /// </summary>
        public ModelContext DbContext
        {
            get
            {
                if (this.dbContext == null)
                    this.dbContext = new ModelContext();
                return this.dbContext;
            }
        }

        public void Commit()
        {
            if (this.DbContext != null)
            {
                this.DbContext.SaveChanges();
            }
        }

        public void Dispose()
        {
            if (this.DbContext != null)
            {
                this.DbContext.Dispose();
                this.dbContext = null;
            }
        }
    }
}